
/**
 * 所有使用SAAS服务端 客户都视为B端客户，所以SDK是以B端开发为需求基础，对接Merch接口
 * @author seeker910
 * @description redjs javascript sdk :hermes-api.js
 * @description 网站相关api 接口
 */ 

var hermesHost = {
     text:'Hermes服务',
     name:'hermes',
     url:'https://hermes.sellerpartner.cn/', 
     // url:'http://localhost:5000/',
     index:'dev/index',
     isLoaded:false,
     useSSL:false,
     controllers:[
         {Name:'User',Path:'User',GetDescription:'GetDes'},
         {Name:'Shop.Cart',Path:'Shop/Cart',GetDescription:'GetDes'},
         {Name:'Goods',Path:'Goods',GetDescription:'GetDes'},
         {Name:'Order',Path:'Order',GetDescription:'GetDes'}
     ]
};

/**
 * 加载api services
 */
Rsd.loadServices(hermesHost,[],function(data,state){
    if(state=='serviceLoaded')
    rsd.app.fire('hermes-api',data);
});
//缓存数据
Rsd.hermes = Rsd.hermes||{};

/**
 * 提交商品到购物车
 * @param {*} evt 
 */
Rsd.hermes.addGoodsToCart = function addGoodsToCart(evt)
{ 
    evt.preventDefault();
    Rsd.submit("hermes.shop.cart.addgoodstocart",this);
} 
/**
 * 移除购物车中的商品
 * @param {*} evt 
 */
Rsd.hermes.removeGoodsFromCart = function removeGoodsFromCart(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.shop.cart.removegoodsfromcart',{},function(resp){
        console.log(resp);
    });
}
/**
 * 获取购物车清单 
 * @param {*} evt 
 */
Rsd.hermes.getCartGoodsList = function getCartGoodsList(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.shop.cart.getcartgoodslist',{},function(resp){
        console.log(resp);
    });
}
/**
 * 提交商品到wishlist
 * @param {*} evt 
 */
Rsd.hermes.addGoodsToWishlist = function addGoodsToWishlist(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.shop.cart.addgoodstowishlist',{},function(resp){
        console.log(resp);
    });
}
/**
 * 移除wishlist中的商品 
 * @param {*} evt 
 */
Rsd.hermes.removeGoodsFromWishlist = function removeGoodsFromWishlist(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.shop.cart.removegoodsfromwishlist',this,function(resp){
        console.log(resp);
    });
}
/**
 * 获取wishlist清单 
 * @param {*} evt 
 */
Rsd.hermes.getWishlist = function getWishlist(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.shop.cart.getwishlist',{},function(resp){
        console.log(resp);
    });
}
/**
 * 获取订单号
 * @param {*} evt 
 */
 Rsd.hermes.getOrderSn = function getOrderSn(evt)
 { 
     evt.preventDefault();
     Rsd.requestService('hermes.Order.GetOrderSn',{},function(resp){
         console.log(resp);
     });
 }
/**
 *  将购物车中的商品提交为订单
 * @param {*} evt 
 */
Rsd.hermes.newOrderFromCart = function newOrderFromCart(evt)
{ 
    evt.preventDefault();
    Rsd.submit('hermes.Order.NewOrderFromCart',{},function(resp){
        console.log(resp);
    });
}

/**
 * 取消订单 
 * @param {*} evt 
 */
Rsd.hermes.cancelOrder = function cancelOrder(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.order.cancel',{},function(resp){
        console.log(resp);
    });
}
/**
 * 订单付款 
 * @param {*} evt 
 */
Rsd.hermes.checkoutOrder = function checkoutOrder(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('paypal.checkout.createorder',{},function(resp){
        console.log(resp);
    });
}
/**
 * 登录
 * @param {*} evt 
 */ 
Rsd.hermes.loginByAccount = function loginByAccount(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.user.loginbyaccount',{},function(resp){
        console.log(resp);
    });
}
/**
 * 使用邮箱注册 
 * @param {*} evt 
 */
Rsd.hermes.registerByEmail = function registerByEmail(evt)
{ 
    evt.preventDefault();
    Rsd.requestService('hermes.user.register',{},function(resp){
        console.log(resp);
    });
}
/**
* 绑定dom事件
*/
document.onready=function()
{  
   //提交订阅
   Rsd.bindEvent("form[rsdtype=Subscrib]","onsubmit",Rsd.submitSubscrib);
   //提交联系我们信息
   Rsd.bindEvent("form[rsdtype=Contact]","onsubmit",Rsd.submitContact);
   //提交商品到购物车
   Rsd.bindEvent("a[rsdtype=addToCart]","onclick",Rsd.addGoodsToCart);
   //移除购物车中的商品
   Rsd.bindEvent("a[rsdtype=removeFromCart]","onclick",Rsd.removeGoodsFromCart);
   //提交商品到wishlist
   Rsd.bindEvent("form[rsdtype=addToWishlist]","onclick",Rsd.addGoodsToWishlist);
   //移除wishlist中的商品
   Rsd.bindEvent("a[rsdtype=removeFromWishlist]","onclick",Rsd.removeGoodsFromWishlist);
   //将购物车中的商品提交为订单 
   Rsd.bindEvent("form[rsdtype=newOrderFromCart]","onsubmit",Rsd.newOrderFromCart);
    //取消订单 
    Rsd.bindEvent("a[rsdtype=cancelOrder]","onclick",Rsd.cancelOrder);
    //订单付款
    Rsd.bindEvent("form[rsdtype=checkoutOrder]","onsubmit",Rsd.checkoutOrder);
    //登录 
    Rsd.bindEvent("form[rsdtype=loginByAccount]","onsubmit",Rsd.loginByAccount);
    //使用邮箱注册
    Rsd.bindEvent("form[rsdtype=registerByEmail]","onsubmit",Rsd.registerByEmail);
}
